//
//  YLAMYNameCell.swift
//  Your Lover AI
//
//  Created by 阿忠 on 2024/6/22.
//

import Foundation
import UIKit

class YLAMYNameCell: UITableViewCell {
    
    //背景
    lazy var backVc: UIView = {
        let view = UIView()
        view.backgroundColor = .clear
        view.layer.cornerRadius = 10.0 // 设置圆角半径为10.0
        view.layer.masksToBounds = true
        return view
    }()
    
    //修改图
    lazy var editImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "set_edit"))
        return image
    }()
    
    //提示
    lazy var titleLab: UILabel = {
        let lab = UILabel()
        lab.text = "Your nickname"
        lab.textColor = UIColor(hex: "FFFFFF")
        lab.font = UIFont.systemFont(ofSize: 15)
        lab.textAlignment = .left
        lab.numberOfLines = 0
        return lab
    }()
    
    //按钮背景
    lazy var editView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: "7157FF")
        view.layer.cornerRadius = 10.0 // 设置圆角半径为10.0
        view.layer.masksToBounds = true
        return view
    }()
    
    //名字
    lazy var nameLab: UILabel = {
        let lab = UILabel()
        lab.text = "Your nickname"
        lab.textColor = UIColor(hex: "FFFFFF")
        lab.font = UIFont.systemFont(ofSize: 17)
        lab.textAlignment = .left
        lab.numberOfLines = 0
        return lab
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .clear
        contentView.addSubview(backVc)
        backVc.addSubview(titleLab)
        backVc.addSubview(editView)
        editView.addSubview(nameLab)
        editView.addSubview(editImg)
        initUI()
    }

    
    func initUI()
    {
        backVc.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }
        
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.top.equalTo(21)
            make.height.equalTo(15)
        }
        
        editView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.top.equalTo(titleLab.snp.bottom).offset(15)
            make.bottom.equalToSuperview()
        }
        
        //检测有没有设置过名字
        if let isName = UserDefaults.standard.string(forKey: "user_name") {
            // isGender 有一个值，可以在这里使用它
            nameLab.text = isName
        } else {
          
        }
        
        nameLab.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.centerY.equalToSuperview()
        }
        
        editImg.snp.makeConstraints { make in
            make.right.equalTo(-16)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(29)
        }
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

